package com.example.demo.route

import com.example.demo.anno.RouteMapping
import com.example.demo.service.getAll
import com.example.demo.service.getRoleById
import com.example.demo.singleton.VertxHolder
import com.example.demo.util.successJson
import io.vertx.ext.web.RoutingContext

/**
 * @author Xu Haidong
 * @date 2023/4/21 9:51
 */
@RouteMapping("/role")
class RoleRoute {

  private val eventBus = VertxHolder.getInstance()?.eventBus()

  @RouteMapping("/getById/:id")
  fun getById(): suspend (RoutingContext) -> Unit {
    return { ctx ->
      val response = ctx.response()
      val id = ctx.pathParam("id")
      response.successJson(getRoleById(id))
    }
  }

  @RouteMapping("/getList")
  fun getList(): suspend (RoutingContext) -> Unit {
    return { ctx ->
      val response = ctx.response()
      response.successJson(getAll())
    }
  }
}
